package individual;

/**
 * Creates a Protector which is attracted to a Prey and repulsive from none. 
 * 
 * @author Ga-Young Joung and Perry Zheng
 * 
 */
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import behavior.Behavior;
import behavior.BoidBehavior;
import behavior.Parameters;

import debugger.Debugger;
import Environment.*;
import utilities.Vector;

public class Protector extends Boid{
	
	static Behavior myBehavior;
	
	/**
	 * Constructs a Protector
	 * @param center the center of the Protector boid
	 * @param size the size
	 * @param velocity the initial velocity of the boid
	 * @param environment the environment it is in
	 * @param parameters the parameter (i.e radius of neighbors)
	 * @param debugger debugger
	 */
	public Protector(Vector center, Dimension size, Vector velocity, Environment environment, Parameters parameters, Debugger debugger) {
		super(center, size, velocity, environment, parameters, debugger);
		myColor = Color.green;
		myBehavior = new BoidBehavior("Prey", 80, "None", 0, myParameters, false);
	}

	/**
	 * Calls the myBehavior's getNextVelocity() method to update
	 * the current Protector given its surrounding moving entities. 
	 */
    public void update (List<MovingEntity> allIndividuals) {
    	myNextVelocity = myBehavior.getNextVelocity(this, allIndividuals);
    	ArrayList<Vector> ret = myEnvironment.getBoundary().getNewPositionAndVelocity(myCenter, myNextVelocity, mySize);
    	myNextVelocity = ret.get(0);
    	myNextCenter = ret.get(1);
    	
        myTrail.add(new Vector(myNextCenter));
        if (myTrail.size() >= myDebugger.myMaxTrail)
        {
            myTrail.remove(0);
        }
    }
}
